package com.graduationproject.scheduled;

import com.graduationproject.Util.RedisUtil;
import com.graduationproject.entity.Dish;
import com.graduationproject.entity.DishMake;
import com.graduationproject.service.Impl.DishMakeServiceImpl;
import com.graduationproject.service.Impl.DishServiceImpl;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class selectRedisData {

    @Resource
    private DishServiceImpl dishService;

    @Resource
    private RedisUtil redisUtil;

//    @Scheduled(cron = "0 57 15  * * ?" , zone = "Asia/Shanghai")
    @Transactional
    @PostConstruct
    public void selectDishAll() {
        List<Dish> list = dishService.selectDishAndMake();
        if(list == null || list.size() < 0) {
            throw new RuntimeException("找不到菜品");
        }
        long days = TimeUnit.DAYS.toSeconds(1);
        redisUtil.set("dishAll", list, days);
    }
}
